#include "Button.h"
#include "UIRender.h"
#include "Theme.h"

void Button::Create(vec2 pos, vec2 size, UINT32 id)
{
	Control::Create(pos, size, id);
}
tstring Button::GetClassName()
{
	return _T("Button");
}

//void Button::onMouseEnter(int x, int y)
//{
//	if (HitTest(vec2(x, y)))
//	{
//		bHovered = true;
//	}
//}
//
//void Button::onMouseLeave(int x, int y)
//{
//	if (!HitTest(vec2(x, y)))
//	{
//		bHovered = false;
//	}
//}

void Button::onMouseButtonDown(int button, int x, int y)
{
	if (HitTest(vec2(x, y)))
	{
		bPressed = true;
	}
}

void Button::onMouseButtonUp(int button, int x, int y)
{
	if (bPressed)
		bPressed = false;
}

void Button::onMouseMove(int x, int y)
{
	bHovered = HitTest(vec2(x, y));
}

bool Button::OnInit()
{
	Control::OnInit();
	return true;
}
void Button::OnDestroy()
{
	Control::OnDestroy();
}
void Button::Draw()
{
	Control::Draw();
	glLineWidth(2);
	Theme::ITheme* theme = Theme::CustomTheme::GetInstance();

	if (bPressed) {
		UIRender::DrawFillRect(pos.x, pos.y, size.x, size.y, theme->GetPressColor());
	}
	else if (bHovered)
	{
		UIRender::DrawFillRect(pos.x, pos.y, size.x, size.y, theme->GetHoverColor());
	}
	else {
		UIRender::DrawFillRect(pos.x, pos.y, size.x, size.y, theme->GetBackColor());
	}
	UIRender::DrawEdgeRect(pos.x, pos.y, size.x, size.y, theme->GetBorderColor());
	UIRender::DrawString(pos, "button");
}
void Button::Resize(int w, int h)
{
	Control::Resize(w, h);
}
